package com.example.base_kotlin_xml.view

import com.blankj.utilcode.util.LogUtils
import com.example.base_kotlin_xml.R
import com.example.base_kotlin_xml.databinding.FragmentGlobalStateBinding
import com.example.base_model.general.GlobalStateManager
import com.example.base_model.view.BaseFragment
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.collectLatest
import javax.inject.Inject

/**
 * @Author: jiangKunKun
 * @CreateDate: 2025/7/30
 * @Description: 测试全局状态
 * @SpittingGrooves
 */
@AndroidEntryPoint
class GlobalStateFragment : BaseFragment<FragmentGlobalStateBinding>() {
    @Inject
    lateinit var globalState: GlobalStateManager

    override fun initObservers() {
        launchAndCollect {
            globalState.appTitle.state.collectLatest {
                LogUtils.d("GlobalStateActivity 当前页面监听appTitle状态变化", it)
            }
        }
    }

    override fun initClickEvents() {
        // 状态管理1
        mBinding.btnChangeStateOne.setOnClickListener {
            globalState.appTitle.update("测试修改标题 一")
        }
        // 状态管理2
        mBinding.btnChangeStateTwo.setOnClickListener {
            globalState.appTitle.update("测试修改标题 二")
        }
        // 状态管理3
        mBinding.btnChangeStateThree.setOnClickListener {
            globalState.appTitle.update("测试修改标题 三")
        }
    }

    override fun initData() {

    }

    override fun attachLayoutRes(): Int = R.layout.fragment_global_state
}